package modele;

import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Vehicule {
	
	private int id;
	private String marque;
	private String modele;
	private int annee;
	private int kilometrage;
	private double prix;
	private int nbExemp;
	
	
	
	public Vehicule(int id, String marque, String modele, int annee,
			int kilometrage, double prix, int nbExemp) {
		super();
		this.id = id;
		this.marque = marque;
		this.modele = modele;
		this.annee = annee;
		this.kilometrage = kilometrage;
		this.prix = prix;
		this.nbExemp = nbExemp;
	}
	public Vehicule() {
		super();
		// TODO Auto-generated constructor stub
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getMarque() {
		return marque;
	}
	public void setMarque(String marque) {
		this.marque = marque;
	}
	public String getModele() {
		return modele;
	}
	public void setModele(String modele) {
		this.modele = modele;
	}
	public int getAnnee() {
		return annee;
	}
	public void setAnnee(int annee) {
		this.annee = annee;
	}
	public int getKilometrage() {
		return kilometrage;
	}
	public void setKilometrage(int kilometrage) {
		this.kilometrage = kilometrage;
	}
	public double getPrix() {
		return prix;
	}
	public void setPrix(double prix) {
		this.prix = prix;
	}
	public int getNbExemp() {
		return nbExemp;
	}
	public void setNbExemp(int nbExemp) {
		this.nbExemp = nbExemp;
	}
	
	@Override
	public String toString() {
		return  id + "|" + marque + "|"
				+ modele + "|" + annee + "|" + kilometrage
				+ "|" + prix + "|" + nbExemp;
	}
	public void readData(Scanner scanner){
	
			try{
				String ligne = scanner.nextLine() ;
				String[] tokens = ligne.split("\\|");
		        this.setId(Integer.parseInt(tokens[0]));
		        this.setMarque(tokens[1]);
		        this.setModele(tokens[2]);
		        this.setAnnee(Integer.parseInt(tokens[3]));
		        this.setKilometrage(Integer.parseInt(tokens[4]));
		       	this.setPrix(Double.parseDouble(tokens[5]));
		        this.setNbExemp(Integer.parseInt(tokens[6]));
		        System.out.println(this.toString());    
		    }
		    catch (NoSuchElementException exception){
		    	System.out.println("Exception : " + exception.getMessage());
		    }
		
	}
	
	public void writeData(PrintWriter printW){
		
			try{
				printW.print("\n"+this.toString());
		    }
			catch(NoSuchElementException exception){
				System.out.println("Exception :" + exception.getMessage());
			}
	}

	@Override
    public boolean equals(Object obj){
        boolean res=false;
        if(this==obj){
            res = true;
        }
        else if(this.getClass().equals(obj.getClass())){
            Vehicule vehic = (Vehicule)obj;
            if((this.marque.equals(vehic.marque))&&(this.modele.equals(vehic.modele))){
                res = true;
            }
        }
        return res;
    }
	
}
